#include <iostream>
#include <vector>

using namespace std;

int numberOfArithmeticSlices(vector<int>& nums) {
    if (nums.size() < 3)
        return 0;
    vector<int> cha;
    for (int i = 1; i < nums.size(); ++i) {
        cha.push_back(nums[i] - nums[i - 1]);
    }

    int cnt = 1;
    int ans = 0;
    for (int i = 1; i < cha.size(); ++i) {
        if (cha[i] != cha[i - 1]) {
            if (cnt >= 2) {
                int k = cnt + 1;
                ans += (1 + k - 2) * (k - 2) / 2;
            }
            cnt = 1;
        } else {
            cnt++;
        }
    }
    if (cnt >= 2) {
        int k = cnt + 1;
        ans += (1 + k - 2) * (k - 2) / 2;
    }
    return ans;
}